/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oalam.bookstore.utils;

import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Administrateur
 */
public class EmailValidator {

    public static boolean validate(String email) {
        // Input the string for validation
        // String email = "xyz@.com";
        // Set the email pattern string
        Pattern p = Pattern.compile(".+@.+\\.[a-z]+");

        // Match the given string with the pattern
        Matcher m = p.matcher(email);

        // check whether match is found
        boolean matchFound = m.matches();

        StringTokenizer st = new StringTokenizer(email, ".");
        String lastToken = null;
        while (st.hasMoreTokens()) {
            lastToken = st.nextToken();
        }

        if (matchFound && lastToken.length() >= 2
                && email.length() - 1 != lastToken.length()) {

            // validate the country code
            return true;
        } else {
            return false;
        }
    }
}
